package com.shop.loan.handler;

import com.shop.loan.mapper.UserByMybatisMapper;
import com.shop.loan.model.User;
import com.shop.loan.model.entity.UserByMybatis;
import com.shop.loan.model.enums.UserStatus;
import com.shop.loan.util.Util;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.OperationHandler;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RecoverUserHandler  implements OperationHandler<User, Void> {

    @Resource
    UserByMybatisMapper userByMybatisMapper;

    @Override
    public String exec(List<User> data, Void unused, String[] param) {
        User user = data.get(0);
        String mobile = user.getMobile();
        if(user.getMobile().contains(Util.prefixDel)){
            mobile = mobile.split(Util.prefixDel)[0];
        }
        String cardNum = user.getCardNum();
        if(user.getCardNum() != null && user.getCardNum().contains(Util.prefixDel)){
            cardNum = cardNum.split(Util.prefixDel)[0];
        }
        UserByMybatis updateUser = new UserByMybatis();
        updateUser.setId(user.getId());
        updateUser.setMobile(mobile);
        updateUser.setCardNum(cardNum);
        updateUser.setUserStatus(UserStatus.normal.getType());
        userByMybatisMapper.updateByPrimaryKeySelective(updateUser);
        return null;
    }
}
